import service from '@/utils/request'
import servicePush from '@/utils/requestPush'

// 统一接口获取
export const getApi = (url: any,data: any) => {
    return service.post(url, data)
}

// 统一接口获取
export const postApi = (url: any,data: any,msg: any = '') => {
    // if (url == '/api/client/sms/code') {
    //     console.log(data);
    //     return new Promise((resolve) => {
    //         resolve({
    //             code: 200,
    //             data: {
    //                 cn: "发送成功",
    //                 en: "发送成功",
    //             }
    //         })
    //     })
    // }
    const headers: any = {
        loading: msg
    }
    return service.post(url, data, headers)
}

// 推送服务器
export const postApiPush = (url: any,data: any,msg: any = '') => {
    const headers: any = {
        loading: msg
    }
    return servicePush.post(url, data, headers)
}

// 获取阿里云直传参数
export const getUploadToken = () => {
    return service.post('/api/direct_upload/upload_web_token')
}

// 获取阿里云直传参数
export const getDashboard = () => {
    return service.post('/api/main/home/dashboard')
}

// 获取用户列表
export const getAdminList = (data: any) => {
    return service.post('/admin/list', data)
}
// 获取用户详情
export const getAdminInfo = (data: any) => {
    return service.post('/admin/edit', data)
}
// 新增或者更新用户员工
export const setAdminInfo = (data: any) => {
    return service.post(data.id == undefined ? '/admin/create' : '/admin/update', data)
}
// 修改密码
export const ChangePassword = (data: any) => {
    return service.post('/admin/update_passwd', data)
}

// 获取部门列表
export const getDepartmentList = (data: any) => {
    return service.post('/admin/department/list', data)
}
// 获取部门权限信息
export const getDepartmentPermission = (data: any) => {
    return service.post('/admin/department_has_permission/get', data)
}

// 获取权限列表
export const getPermissionList = (data: any) => {
    let url = '/admin/permission/list'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/list'
    }
    return service.post(url, data)
}
// 新增权限
export const addPermission = (data: any) => {
    let url = '/admin/permission/store'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/store'
    }
    return service.post(url, data)
}
// 获取权限信息
export const editPermission = (data: any) => {
    let url = '/admin/permission/edit'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/edit'
    }
    return service.post(url, data)
}
// 更新权限
export const updatePermission = (data: any) => {
    let url = '/admin/permission/update'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/update'
    }
    return service.post(url, data)
}
// 更新用户权限
export const updateUserPermission = (data: any) => {
    let url = '/admin/permission/update_user_permission'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/update_user_permission'
    }
    return service.post(url, data)
}

// 获取用户权限
export const getUserPermission = (data: any) => {
    let url = '/admin/permission/get_all_permission'
    if (localStorage.getItem('user_system') == '2') {
        url = '/api/client/permission/get_all_permission'
    }
    return service.post(url, data)
}
// 产品类型-开始
export const useProductTypeListApi = () => {
	return service.post('/api/strator/product/type/tree/all')
}

export const useProductTypeAddApi = (data: any) => {
	return service.post(data.id ? '/api/strator/product/type/modify' : '/api/strator/product/type/add', data)
}

export const useProductTypeApi = (data: any) => {
	return service.post('/api/strator/product/type/detail', data)
}
// 产品类型-结束
// 产品规格-开始
export const useProductSpecListApi = () => {
	return service.post('/api/strator/product/spec/tree/all')
}

export const useProductSpecAddApi = (data: any) => {
	return service.post(data.id ? '/api/strator/product/spec/modify' : '/api/strator/product/spec/add', data)
}

export const useProductSpecApi = (data: any) => {
	return service.post('/api/strator/product/spec/detail', data)
}
// 产品规格-结束
// 产品属性-开始
export const useProductAttrListApi = () => {
	return service.post('/api/strator/product/attr/tree/all')
}

export const useProductAttrAddApi = (data: any) => {
	return service.post(data.id ? '/api/strator/product/attr/modify' : '/api/strator/product/attr/add', data)
}

export const useProductAttrApi = (data: any) => {
	return service.post('/api/strator/product/attr/detail', data)
}
// 产品属性-结束
// 获取产品列表
export const getProductList = (data: any) => {
	return service.post('/api/strator/pro/list', data)
}
// 新增-修改产品
export const addProduct = (data: any) => {
	return service.post(data.id ? '/api/strator/pro/modify' : '/api/strator/pro/add', data)
}
// 查看所有产品
export const getProductListAll = (id: number) => {
	return service.post('/api/strator/pro/listall', {id})
}
// 查看产品详情
export const getProduct = (id: number) => {
	return service.post('/api/strator/pro/detail', {id})
}
// 获取产品sku列表
export const getProductSkuList = (data: any) => {
	return service.post('/api/strator/product/list', data)
}
// 获取产品批次列表
export const getBatchList = (data: any) => {
	return service.post('/api/strator/product/getBatchList', data ,{hideloading:true})
}
// 查看所有产品SKU
export const getProductSkuAll = (id: number) => {
	return service.post('/api/strator/product/listall', {id})
}
// 新增-修改sku产品
export const addProductSku = (data: any) => {
	return service.post(data.id ? '/api/strator/product/modify' : '/api/strator/product/add', data)
}
// 查看产品sku详情
export const getProductSku = (id: number) => {
	return service.post('/api/strator/product/detail', {id})
}
// 删除产品sku
export const delProductSku = (id: number) => {
	return service.post('/api/strator/product/delete', {id})
}
// 查看产品sku详情
export const getProductTotal = (data: any) => {
	return service.post('/api/strator/product/inventory/total', data)
}
// 导出产品库存信息
export const exportproduct = (data: any) => {
	return service.post('/api/strator/product/exportproduct', data)
}


// 阿里云直传oss参数配置获取-图片
export const getOssImage = (data: any) => {
    return service.post('/api/upload/oss/image/direct/policy', data)
}
// 获取配置信息
export const getSystemConfig = (key: any) => {
    return service.post('/api/system/config/get/by/key', {key: key})
}
// 查看留言
export const getFeedBackList = (id: number) => {
	return service.post('/api/shop/feedback/list', {id})
}
// 新增-修改留言
export const addFeedBack = (data: any) => {
	return service.post(data.id ? '/api/shop/feedback/modify' : '/api/shop/feedback/add', data)
}
// 查看留言详情
export const getFeedBack = (id: number) => {
	return service.post('/api/shop/feedback/detail', {id})
}
// 删除留言
export const delFeedBack = (id: number) => {
	return service.post('/api/shop/feedback/delete', {id})
}

// 获取基本配置

export const getConfigTableList = (data: any) => {
    return service.post('/api/shop/config/list', data)
}
// 新增-修改基本配置
export const addConfigTable = (data: any) => {
	return service.post(data.id ? '/api/shop/config/modify' : '/api/shop/config/add', data)
}
// 查看基本配置详情
export const getConfigTable = (id: number) => {
	return service.post('/api/shop/config/detail', {id})
}
// 删除基本配置
export const delConfigTable = (id: number) => {
	return service.post('/api/shop/config/delete', {id})
}